<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of browser
 *
 * @author Andriy
 */
class Browser
{
    protected $_cookie = null;
    
    public function get( $url,  $post_data = null )
    {
//        $url = str_replace( "&amp;", "&", urldecode(trim($url)) );
        $ch = curl_init();
        curl_setopt( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.205 Safari/534.16" );
        curl_setopt( $ch, CURLOPT_URL, $url );
        
        if( !$this->_cookie )
        {
            $this->_cookie = tempnam ("tmp", "CURLCOOKIE");
        }
        curl_setopt( $ch, CURLOPT_COOKIEJAR, $this->_cookie );
        curl_setopt( $ch, CURLOPT_COOKIEFILE, $this->_cookie );
        
        curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
        curl_setopt( $ch, CURLOPT_ENCODING, "" );
        curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
        curl_setopt( $ch, CURLOPT_AUTOREFERER, true );
        
        if( $post_data )
        {
            curl_setopt($ch, CURLOPT_POST, 1); 
            curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); 
        }
        
        $content = curl_exec( $ch );
        curl_close ( $ch );
        
        return $content;
    }
    
    
}

?>
